package com.baizhi.action.front;

import com.baizhi.entity.Book;
import com.baizhi.entity.Category;
import com.baizhi.service.BookService;
import com.baizhi.service.CategoryService;
import com.baizhi.service.impl.BookServiceImpl;
import com.baizhi.service.impl.CategoryServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class BookAction {

    private List<Category> categories;

    private List<Book> books1;
    private List<Book> books2;
    private List<Book> books3;
    private List<Book> books4;

    private String bookId;
    private String firstId;
    private String secondId;

    private Integer pageNum;
    private Integer pageSize;
    private PageInfo<Book> pageInfo;
    private Book book;

    private Category category;

    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    public List<Book> getBooks1() {
        return books1;
    }

    public void setBooks1(List<Book> books1) {
        this.books1 = books1;
    }

    public List<Book> getBooks2() {
        return books2;
    }

    public void setBooks2(List<Book> books2) {
        this.books2 = books2;
    }

    public List<Book> getBooks3() {
        return books3;
    }

    public void setBooks3(List<Book> books3) {
        this.books3 = books3;
    }

    public List<Book> getBooks4() {
        return books4;
    }

    public void setBooks4(List<Book> books4) {
        this.books4 = books4;
    }

    public String getFirstId() {
        return firstId;
    }

    public void setFirstId(String firstId) {
        this.firstId = firstId;
    }

    public String getSecondId() {
        return secondId;
    }

    public void setSecondId(String secondId) {
        this.secondId = secondId;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public PageInfo<Book> getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(PageInfo<Book> pageInfo) {
        this.pageInfo = pageInfo;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public String getBookId() {
        return bookId;
    }

    public void setBookId(String bookId) {
        this.bookId = bookId;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public String main(){
        BookService bookService=new BookServiceImpl();
        CategoryService categoryService=new CategoryServiceImpl();
        categories=categoryService.selectCategoryLevels1s();
        books1=bookService.selectByRecommend();
        books2=bookService.selectByHotSale();
        books3=bookService.selectByNewBook();
        books4=bookService.selectByNewBookHotSale();
        return "success";
    }

    public String secondPage(){
        CategoryService categoryService=new CategoryServiceImpl();
        BookService bookService=new BookServiceImpl();
        categories=categoryService.selectCategoryByFirstId(firstId);

        category=categoryService.selectCategoryById(firstId);
        if(pageNum==null){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=2;
        }
        //books1只是不想再写个books了
        PageHelper.startPage(pageNum,pageSize);
        books1=bookService.selectBookByCategoryId(firstId,secondId);
        pageInfo=new PageInfo<>(books1,20);
        //secondId=secondId;
        //firstId=firstId;
        return "showSecondPage";
    }


    public String showBookDetail(){
        BookService bookService=new BookServiceImpl();
        book = bookService.selectBookById(bookId);
        return "showDetail";
    }
}
